class PostServiceTests extends GroovyTestCase {

  void testAPostsTagsCanBePopulatedFromAString() {
    def tagString = "foo bar"
    def post = new Post(title:"Title", teaser:"teaser", content:"content")
    def postService = new PostService()
    postService.populateTags(post, tagString)
    assertEquals(2, post.tags.size())
    post.save()
    assertEquals(2, Tag.list().size())
    assertEquals(1, Post.list().size())
    def loadedPost = Post.findByTitle("Title")
    assertEquals(2, loadedPost.tags.size())
  }

  void testTagsOnThePostThatAreNotInTheStringShouldBeRemoved() {
    def tagString = "foo bar"
    def post = new Post().addToTags(new Tag(name:"removed"))
    def postService = new PostService()
    postService.populateTags(post, tagString)
    assertEquals(2, post.tags.size())
    assertFalse(post.hasTag("removed"))
  }

}